import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LoginGUI extends MyEvent {
	private JFrame jLoginForm;
	private JButton jbtnSignIn, jbtnSignUp, jbtnExit;
	private JTextField jtxtUsername, jtxtPassword, jtxtPort;
	private JLabel jlblUsername, jlblPassword, jlblPort;
	private JPanel jPanel;
	
	public LoginGUI() {
		jLoginForm = new JFrame("Login");
		jPanel = new JPanel();

		jbtnSignIn = new JButton("Sign In");
		jbtnSignIn.addActionListener(this);
		jbtnExit = new JButton("Exit");
		jbtnExit.addActionListener(this);

		jtxtUsername = new JTextField(9);
		jtxtPassword = new JTextField(9);
		jtxtPort = new JTextField(9);

		jlblUsername = new JLabel("Username");
		jlblPassword = new JLabel("Password");
		jlblPort = new JLabel("Port");
	}

	public void CreateGUI() {
		jLoginForm.setLayout(new FlowLayout());
		
		jPanel.add(jlblPort);
		jPanel.add(jtxtPort);
		jPanel.add(jlblUsername);
		jPanel.add(jtxtUsername);
		jPanel.add(jlblPassword);
		jPanel.add(jtxtPassword);
		jPanel.add(jbtnSignIn);
		jPanel.add(jbtnExit);

		jLoginForm.add(jPanel);
		jLoginForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jLoginForm.pack();
		jLoginForm.setVisible(true);
	}

	public static void main(String[] args) {
		LoginGUI gui = new LoginGUI();
		gui.CreateGUI();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == jbtnSignIn){
			jLoginForm.setVisible(false);
			ListUserOnlineGUI lstUser = new ListUserOnlineGUI(jtxtUsername.getText().trim());
			lstUser.CreateGUI();
		}else if(e.getSource() == jbtnExit){
			jLoginForm.setVisible(false);
		}
	}
}
